<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *项目管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('start','off');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择相册！','error');
	}
}
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','title','cid','status','image','images','remark','paixu','createtime');
	$list=pdo_getslice('jy_cmsphoto_photo',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['url']=custom_url('jy_cmsphoto/photo//id='.$item['id'],true);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'相册列表'),
			array('op'=>'edit','title'=>'添加相册'),
		),
		'list'=>array('data'=>'list','edit'=>true,'list'=>array(
			array('name'=>'title','title'=>'相册名称','type'=>'string'),		
			array('name'=>'image','title'=>'相册封面','type'=>'image'),		
		//	array('name'=>'status','title'=>'是否启用','type'=>'switch','set'=>'set'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'url','title'=>'复制链接','type'=>'copy'),
			array('name'=>'url','title'=>'二维码','type'=>'ewm'),
		),'action' => 
		    array (
			       array('type'=>'post','op'=>'ok','title'=>'审核','message'=>'确定通过该相册吗！','show'=>array('status'=>'0')),
			       array('type'=>'post','op'=>'no','title'=>'忽略','message'=>'确定忽略该相册吗！','show'=>array('status'=>'0')),
				   ),),
			
		
		'search'=>array(array('name'=>'title','title'=>'相册名称','width'=>'15','type'=>'string'),array('name'=>'status','type'=>'radio','options'=>'status','width'=>'15','title'=>'状态'),)
	);
	$return['status']=array('待审核','已审核','审核不通过');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_cmsphoto_photo',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['images']=json_decode($item['images'],true);
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回相册列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
						array(
							'title'=>'基本信息',
							'list'=>array(
								array('type'=>'string','title'=>'相册名称','name'=>'title','help'=>''),
								array('type'=>'image','title'=>'相册封面图','name'=>'image','help'=>''),
								array('type'=>'images','title'=>'相册图片','name'=>'images','help'=>''),
								array('type'=>'audio','title'=>'相册背景音乐','name'=>'audio','help'=>''),
								array('type'=>'select','options'=>'cname','option_title'=>'title','title'=>'分类','name'=>'cid','help'=>''),
								array('type'=>'string','title'=>'排序','name'=>'paixu','help'=>'填写数字，按从小到大排序展示'),
							//	array('type'=>'switch','title'=>'首页展示','name'=>'isshow','help'=>'设置是否首页展示'),
								array('type'=>'switch','title'=>'是否启用','name'=>'status','help'=>'设置是否启用'),
								array('type'=>'text','title'=>'相册说明','name'=>'remark','help'=>''),
							)
						),
			
			)
	);
	$return['cname']=pdo_getall('jy_cmsphoto_classify',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(empty($postdata['title'])){
		exi('请完善相册名称','error');
	}
	if(empty($postdata['image'])){
		exi('请完善相册封面','error');
	}
	if(!$postdata['cid']){
		exi('请选择分类','error');
	}
	if(empty($postdata['images'])){
		exi('请上传批量图','error');
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'image'=>trim($postdata['image']),
		'cid'=>intval($postdata['cid']),
		'images'=>ijson_encode($postdata['images']),
		'audio'=>trim($postdata['audio']),
		'remark'=>trim($postdata['remark']),
		'status'=>intval($postdata['status']),
	//	'isshow'=>intval($postdata['isshow']),
		'paixu'=>intval($postdata['paixu']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_cmsphoto_photo',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_cmsphoto_photo',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_cmsphoto_photo',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的相册！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_cmsphoto_photo',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	if(isset($post['isshow'])){
		pdo_update('jy_cmsphoto_photo',array('isshow'=>intval($post['isshow'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='no'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要忽略的相册！','error');
	}
	pdo_update('jy_cmsphoto_photo',array('status'=>2),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	exi('已忽略该相册！');
}
if($_RQ['op']=='ok'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要审核的相册！','error');
	}
	pdo_update('jy_cmsphoto_photo',array('status'=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	exi('已审核通过该相册！');
}